if (datebegin = $('.range_inputs .daterangepicker_start_input input.input-mini').val() == $('.range_inputs .daterangepicker_end_input input.input-mini').val()){
			var datesearch = $('.range_inputs .daterangepicker_start_input input.input-mini').val();
			var datesearchoffical = datesearch[6]+datesearch[7]+datesearch[8]+datesearch[9]+'-'+datesearch[0]+datesearch[1]+'-'+datesearch[3]+datesearch[4];
			//alert('gg');
			if ($("#barchart").length) {
				var getUrl= "http://piwik.datamyze.com/?module=API&method=UserSettings.getResolution&idSite="+piwik_id+"&period=day&date="+datesearchoffical+"&format=JSON&token_auth=717135ae2ebfd8f313284614f70a6765";
				$.ajaxSetup({ 
					scriptCharset: "UTF-8" , 
					contentType: "application/json; charset=UTF-8",
					type:"GET"
				});
				$("#barchart").html('<img src="../img/loading2.gif" />');
				$.ajax({
					url: getUrl,
					crossDomain:true,
					dataType : 'jsonp',
					jsonp : 'jsoncallback',
					//jsonpCallback  : 'foo',
					crossDomain : true,
					success: function(data) {
						for (var i=0;i<(data.length - 1);i++){
							for (var j=i+1;j<data.length;j++){ 
								if( data[i].sum_visit_length < data[j].sum_visit_length ){
									k = data[i];
									data[i] = data[j];
									data[j] = k;
								}
							}
						}
						var sum = 0;
						for (var i=0;i<(data.length);i++){ 	
							if (i>4){
								sum = sum + data[i].sum_visit_length;
								//data[i].sum_visit_length = 0;
								delete data[i];
							} else{
								
							}
						}
						data.length = 6;
						data.forEach(function(entry) {
							entry.data = entry.sum_visit_length;
						});
							
							data[5] = { bounce_count: 19,  data: sum , label: "Other", max_actions: 681, nb_actions: 1180, nb_uniq_visitors: 56 ,nb_visits: 56, nb_visits_converted: 0, sum_visit_length: sum };
							
							$.plot($("#barchart"), data,
							{
								colors: ["#0066FF","#009999","#660033", "#FF0000", "#99FF66" , "#FF66FF"],
								series: {
									pie: {
										show: true,
										label: {
											show: false,
											formatter: function(label, series){
												return '<div style="font-size:11px;text-align:center;padding:4px;color:white;">'+label+'<br/>'+Math.round(series.percent)+'%</div>';
											},
											threshold: 0.1
										}
									}
								},
								legend: {
									show: true,
									noColumns: 1, // number of colums in legend table
									labelFormatter: null, // fn: string -> string
									labelBoxBorderColor: "#444", // border color for the little label boxes
									container: null, // container (as jQuery object) to put legend in, null means default on top of graph
									position: "ne", // position of default legend container within plot
									margin: [5, 10], // distance from grid edge to default legend container within plot
									backgroundOpacity: 0 // set to 0 to avoid background
								},
								grid: {
									hoverable: false,
									clickable: false
								}
							});
						
					},
					error: function(data) {console.log(data);},
				});
			}
			
			
			if ($("#pie-chart").length) {
				
				var getUrl="http://piwik.datamyze.com/?module=API&method=DevicesDetection.getBrowserFamilies&idSite="+piwik_id+"&period=day&date="+datesearchoffical+"&format=JSON&token_auth=717135ae2ebfd8f313284614f70a6765";
				
				$.ajaxSetup({ 
					scriptCharset: "UTF-8" , 
					contentType: "application/json; charset=UTF-8",
					type:"GET"
				});
				$("#pie-chart").html('<img src="../img/loading2.gif" />');
				$.ajax({
					url: getUrl,
					crossDomain:true,
					dataType : 'jsonp',
					jsonp : 'jsoncallback',
					//jsonpCallback  : 'foo',
					crossDomain : true,
					success: function(data) {
						for (var i=0;i<(data.length - 1);i++){
							for (var j=i+1;j<data.length;j++){ 
								if( data[i].sum_visit_length < data[j].sum_visit_length ){
									k = data[i];
									data[i] = data[j];
									data[j] = k;
								}
							}
						}
						//console.log(data);
						d2 = [];
						var i = 0;
						data.forEach(function(entry) {
							entry.data = entry.sum_visit_length;
							kak = [i, entry.sum_visit_length]
							d2.push(kak);
							i++;
						});
						console.log(d2);
						$.plot($("#pie-chart"), [
							{
								series:{
									bars:{
										show:true
									}
								},
								data: d2, 
								//label: "d1",
								grid :{
									hoverable: true,
									clickable: true,
									tickcolor: "#dddddd",
									borderWidth:0
								},
								bars: {
									align: "center",
									show: true,
									horizontal:false,
									barWidth: 0.5,
									fill: true,
								},
								xaxis: {
									position: "top",
									tickSize : 4,
									ticks: ["zero", "one" ,"two", "three", "Four", "Five", "Six", "Seven","Eight", "Nine"]
								},
								
								color:  "#FA5833",
							}]);
					},
					error: function(data) {
						console.log(data);
					}
				});
			}
			/*
			if ($("#pie-chart").length) {
				var getUrl="http://piwik.datamyze.com/?module=API&method=DevicesDetection.getBrowserFamilies&idSite="+piwik_id+"&period=day&date="+datesearchoffical+"&format=JSON&token_auth=717135ae2ebfd8f313284614f70a6765";
				$.ajaxSetup({ 
					scriptCharset: "UTF-8" ,
					contentType: "application/json; charset=UTF-8",
					type:"GET"
				});
				$("#pie-chart").html('<img src="../img/loading2.gif" />');
				$.ajax({
					url: getUrl,
					crossDomain:true,
					dataType : 'jsonp',
					jsonp : 'jsoncallback',
					jsonpCallback  : 'foo',
					crossDomain : true,
						success: function(data) {
							data.forEach(function(entry) {
								entry.data = entry.sum_visit_length;
							});
							$.plot($("#pie-chart"), data,
							{
								colors: [lightBlue, mediumBlue, darkBlue, "#333", "#ccc" , "#FFFF00" ,"#FF0000","#f0f0f0","#66FF33"],
								series: {
									pie: {
										show: true,
										label: {
											show: false,
											formatter: function(label, series){
												return '<div style="font-size:11px;text-align:center;padding:4px;color:white;">'+label+'<br/>'+Math.round(series.percent)+'%</div>';
											},
											threshold: 0.1
										}
									}
								},
								legend: {
									show: true,
									noColumns: 1, // number of colums in legend table
									labelFormatter: null, // fn: string -> string
									labelBoxBorderColor: "#444", // border color for the little label boxes
									container: null, // container (as jQuery object) to put legend in, null means default on top of graph
									position: "ne", // position of default legend container within plot
									margin: [5, 10], // distance from grid edge to default legend container within plot
									backgroundOpacity: 0 // set to 0 to avoid background
								},
								grid: {
									hoverable: false,
									clickable: false
								}
							});
						}, 
						error: function(data) { console.log(data); }, 
				});
			}*/
			if ($("#area-chart").length) {
				var datebegin = $('.range_inputs .daterangepicker_start_input input.input-mini').val();
				var dateend = $('.range_inputs .daterangepicker_end_input input.input-mini').val();
				datebeginoffical = datebegin[6]+datebegin[7]+datebegin[8]+datebegin[9]+'-'+datebegin[0]+datebegin[1]+'-'+datebegin[3]+datebegin[4];
				dateendoffical = dateend[6]+dateend[7]+dateend[8]+dateend[9]+'-'+dateend[0]+dateend[1]+'-'+dateend[3]+dateend[4];
				var getUrl="http://piwik.datamyze.com/?module=API&method=DevicesDetection.getBrowserFamilies&idSite="+piwik_id+"&period=day&date="+datesearchoffical+"&format=JSON&token_auth=717135ae2ebfd8f313284614f70a6765";
				
				var getUrl="http://piwik.datamyze.com/?module=API&method=UserSettings.getMobileVsDesktop&idSite="+piwik_id+"&period=day&date="+datesearchoffical+"&format=JSON&token_auth=717135ae2ebfd8f313284614f70a6765";
				console.log(getUrl);
				$.ajaxSetup({ 
					scriptCharset: "UTF-8" ,
					contentType: "application/json; charset=UTF-8",
					type:"GET"
				});
				$("#area-chart").html('<img src="../img/loading2.gif" />');
				$.ajax({
					url: getUrl,
					crossDomain:true,
					dataType : 'jsonp',
					jsonp : 'jsoncallback',
					jsonpCallback  : 'foo',
					crossDomain : true,
						success: function(data) {
							data.forEach(function(entry) {
								entry.data = entry.sum_visit_length;
							});
							$.plot($("#area-chart"), data,
							{
								colors: [ "#3366FF" ,"#009900","#FF0000"],
								series: {
									pie: { 
										show: true,
										radius: 1,
										label: {
											show: true,
											radius: 2/3,
											formatter: function(label, series){
												return '<div style="font-size:11px;text-align:center;padding:4px;color:white;">'+label+'<br/>'+(series.percent).toFixed(2)+'%</div>';
											},
											threshold: 0.1
										}
									}
								},
								legend: {
									show: false
								}
							});
						}, 
						error: function(data) { console.log(data); }, 
				});
			}
			
			
			if ($("#donut-chart").length) {
				var getUrl= "http://piwik.datamyze.com/?module=API&method=DevicesDetection.getType&idSite="+piwik_id+"&period=day&date="+datesearchoffical+"&format=JSON&token_auth=717135ae2ebfd8f313284614f70a6765";
				$.ajaxSetup({ 
					scriptCharset: "UTF-8" , 
					contentType: "application/json; charset=UTF-8",
					type:"GET"
				});
				$("#donut-chart").html('<img src="../img/loading2.gif" />');
				$.ajax({
					url: getUrl,
					crossDomain:true,
					dataType : 'jsonp',
					jsonp : 'jsoncallback',
					//jsonpCallback  : 'foo',
					crossDomain : true,
						success: function(data) {
							data.forEach(function(entry) {
								entry.data = entry.sum_visit_length;
							});
							$.plot($("#donut-chart"), data,
								{
									colors: [lightBlue, mediumBlue, darkBlue, darkPlum, "#FFFF00"],
									series: {
										pie: {
											innerRadius: 0.5,
											show: true
										}
									}
								});
							
						},
						error: function(data) { console.log(data); }, 
					});
					
				var data = [];
				var series = 3;
				for( var i = 0; i<series; i++)
				{
					data[i] = { label: "Series "+(i+1), data: Math.floor(Math.random()*100)+1 }
				}
			}
		}else {
			if ($("#barchart").length) {
				var datebegin = $('.range_inputs .daterangepicker_start_input input.input-mini').val();
				var dateend = $('.range_inputs .daterangepicker_end_input input.input-mini').val();
				var datebeginoffical = datebegin[6]+datebegin[7]+datebegin[8]+datebegin[9]+'-'+datebegin[0]+datebegin[1]+'-'+datebegin[3]+datebegin[4];
				var dateendoffical = dateend[6]+dateend[7]+dateend[8]+dateend[9]+'-'+dateend[0]+dateend[1]+'-'+dateend[3]+dateend[4];
				var getUrl= "http://piwik.datamyze.com/?module=API&method=UserSettings.getResolution&idSite="+piwik_id+"&period=range&date="+datebeginoffical+","+dateendoffical+"&format=JSON&token_auth=717135ae2ebfd8f313284614f70a6765";
				$.ajaxSetup({ 
					scriptCharset: "UTF-8" , 
					contentType: "application/json; charset=UTF-8",
					type:"GET"
				});
				$("#barchart").html('<img src="../img/loading2.gif" />');
				$.ajax({
					url: getUrl,
					crossDomain:true,
					dataType : 'jsonp',
					jsonp : 'jsoncallback',
					//jsonpCallback  : 'foo',
					crossDomain : true,
					success: function(data) {
						for (var i=0;i<(data.length - 1);i++){
							for (var j=i+1;j<data.length;j++){ 
								if( data[i].sum_visit_length < data[j].sum_visit_length ){
									k = data[i];
									data[i] = data[j];
									data[j] = k;
								}
							}
						}
						var sum = 0;
						for (var i=0;i<(data.length);i++){ 	
							if (i>4){
								sum = sum + data[i].sum_visit_length;
								//data[i].sum_visit_length = 0;
								delete data[i];
							} else{
								
							}
						}
						data.length = 6;
						data.forEach(function(entry) {
							entry.data = entry.sum_visit_length;
						});
							
							data[5] = { bounce_count: 19,  data: sum , label: "Other", max_actions: 681, nb_actions: 1180, nb_uniq_visitors: 56 ,nb_visits: 56, nb_visits_converted: 0, sum_visit_length: sum };
							
							$.plot($("#barchart"), data,
							{
								colors: ["#0066FF","#009999","#660033", "#FF0000", "#99FF66" , "#FF66FF"],
								series: {
									pie: {
										show: true,
										label: {
											show: false,
											formatter: function(label, series){
												return '<div style="font-size:11px;text-align:center;padding:4px;color:white;">'+label+'<br/>'+Math.round(series.percent)+'%</div>';
											},
											threshold: 0.1
										}
									}
								},
								legend: {
									show: true,
									noColumns: 1, // number of colums in legend table
									labelFormatter: null, // fn: string -> string
									labelBoxBorderColor: "#444", // border color for the little label boxes
									container: null, // container (as jQuery object) to put legend in, null means default on top of graph
									position: "ne", // position of default legend container within plot
									margin: [5, 10], // distance from grid edge to default legend container within plot
									backgroundOpacity: 0 // set to 0 to avoid background
								},
								grid: {
									hoverable: false,
									clickable: false
								}
							});
						
					},
					error: function(data) {console.log(data);},
				});
			}
			
			if ($("#pie-chart").length) {
				//piwik_id
				var datebegin = $('.range_inputs .daterangepicker_start_input input.input-mini').val();
				var dateend = $('.range_inputs .daterangepicker_end_input input.input-mini').val();
				var datebeginoffical = datebegin[6]+datebegin[7]+datebegin[8]+datebegin[9]+'-'+datebegin[0]+datebegin[1]+'-'+datebegin[3]+datebegin[4];
				var dateendoffical = dateend[6]+dateend[7]+dateend[8]+dateend[9]+'-'+dateend[0]+dateend[1]+'-'+dateend[3]+dateend[4];
				var getUrl="http://piwik.datamyze.com/?module=API&method=DevicesDetection.getBrowserFamilies&idSite="+piwik_id+"&period=range&date="+datebeginoffical+","+dateendoffical+"&format=JSON&token_auth=717135ae2ebfd8f313284614f70a6765";
				//console.log(getUrl);
				$.ajaxSetup({ 
					scriptCharset: "UTF-8" , 
					contentType: "application/json; charset=UTF-8",
					type:"GET"
				});
				$("#pie-chart").html('<img src="../img/loading2.gif" />');
				$.ajax({
					url: getUrl,
					crossDomain:true,
					dataType : 'jsonp',
					jsonp : 'jsoncallback',
					//jsonpCallback  : 'foo',
					crossDomain : true,
					success: function(data) {
						for (var i=0;i<(data.length - 1);i++){
							for (var j=i+1;j<data.length;j++){ 
								if( data[i].sum_visit_length < data[j].sum_visit_length ){
									k = data[i];
									data[i] = data[j];
									data[j] = k;
								}
							}
						}
						//console.log(data);
						d2 = [];
						var i = 0;
						data.forEach(function(entry) {
							entry.data = entry.sum_visit_length;
							kak = [i, entry.sum_visit_length]
							d2.push(kak);
							i++;
						});
						//console.log(d2);
						$.plot($("#pie-chart"), [
							{
								series:{
									bars:{
										show:true
									}
								},
								data: d2, 
								//label: "d1",
								grid :{
									hoverable: true,
									clickable: true,
									tickcolor: "#dddddd",
									borderWidth:0
								},
								bars: {
									align: "center",
									show: true,
									horizontal:false,
									barWidth: 0.5,
									fill: true,
								},
								xaxis: {
									position: "top", // or "top"
									//tickSize : 4,
									ticks: [
										[0,'Zero'],[1,'One'],[2,'Two'],[3,'Three'],[4,'Five'],[5,'Five'],[6,'Six'],[7,'Seven'],[8,'Eight'],[9,'Nine']
									],
								},
								yaxis: {
									autoscaleMargin: 0.02,
									position: "right" // or "right"
								},
								color:  "#FA5833",
							}]);
					},
					error: function(data) {
						console.log(data);
					}
				});
			}
			/*
			if ($("#pie-chart").length) {
				var datebegin = $('.range_inputs .daterangepicker_start_input input.input-mini').val();
				var dateend = $('.range_inputs .daterangepicker_end_input input.input-mini').val();
				datebeginoffical = datebegin[6]+datebegin[7]+datebegin[8]+datebegin[9]+'-'+datebegin[0]+datebegin[1]+'-'+datebegin[3]+datebegin[4];
				dateendoffical = dateend[6]+dateend[7]+dateend[8]+dateend[9]+'-'+dateend[0]+dateend[1]+'-'+dateend[3]+dateend[4];

				var getUrl="http://piwik.datamyze.com/?module=API&method=DevicesDetection.getBrowserFamilies&idSite="+piwik_id+"&period=range&date="+datebeginoffical+","+dateendoffical+"&format=JSON&token_auth=717135ae2ebfd8f313284614f70a6765";
				console.log(getUrl);
				$.ajaxSetup({ 
					scriptCharset: "UTF-8" ,
					contentType: "application/json; charset=UTF-8",
					type:"GET"
				});
				$("#pie-chart").html('<img src="../img/loading2.gif" />');
				$.ajax({
					url: getUrl,
					crossDomain:true,
					dataType : 'jsonp',
					jsonp : 'jsoncallback',
					jsonpCallback  : 'foo',
					crossDomain : true,
						success: function(data) {
							data.forEach(function(entry) {
								entry.data = entry.sum_visit_length;
							});
							$.plot($("#pie-chart"), data,
							{
								colors: [lightBlue, mediumBlue, darkBlue, "#333", "#ccc" , "#FFFF00" ,"#FF0000","#f0f0f0","#66FF33"],
								series: {
									pie: {
										show: true,
										label: {
											show: false,
											formatter: function(label, series){
												return '<div style="font-size:11px;text-align:center;padding:4px;color:white;">'+label+'<br/>'+Math.round(series.percent)+'%</div>';
											},
											threshold: 0.1
										}
									}
								},
								legend: {
									show: true,
									noColumns: 1, // number of colums in legend table
									labelFormatter: null, // fn: string -> string
									labelBoxBorderColor: "#444", // border color for the little label boxes
									container: null, // container (as jQuery object) to put legend in, null means default on top of graph
									position: "ne", // position of default legend container within plot
									margin: [5, 10], // distance from grid edge to default legend container within plot
									backgroundOpacity: 0 // set to 0 to avoid background
								},
								grid: {
									hoverable: false,
									clickable: false
								}
							});
						}, 
						error: function(data) { console.log(data); },
				});
			}
			*/
			if ($("#area-chart").length) {
				var datebegin = $('.range_inputs .daterangepicker_start_input input.input-mini').val();
				var dateend = $('.range_inputs .daterangepicker_end_input input.input-mini').val();
				datebeginoffical = datebegin[6]+datebegin[7]+datebegin[8]+datebegin[9]+'-'+datebegin[0]+datebegin[1]+'-'+datebegin[3]+datebegin[4];
				dateendoffical = dateend[6]+dateend[7]+dateend[8]+dateend[9]+'-'+dateend[0]+dateend[1]+'-'+dateend[3]+dateend[4];

				
				var getUrl="http://piwik.datamyze.com/?module=API&method=UserSettings.getMobileVsDesktop&idSite="+piwik_id+"&period=range&date="+datebeginoffical+","+dateendoffical+"&format=JSON&token_auth=717135ae2ebfd8f313284614f70a6765";
				console.log(getUrl);
				$.ajaxSetup({ 
					scriptCharset: "UTF-8" ,
					contentType: "application/json; charset=UTF-8",
					type:"GET"
				});
				$("#area-chart").html('<img src="../img/loading2.gif" />');
				$.ajax({
					url: getUrl,
					crossDomain:true,
					dataType : 'jsonp',
					jsonp : 'jsoncallback',
					jsonpCallback  : 'foo',
					crossDomain : true,
						success: function(data) {
							data.forEach(function(entry) {
								entry.data = entry.sum_visit_length;
							});
							$.plot($("#area-chart"), data,
							{
								colors: [ "#3366FF" ,"#009900","#FF0000"],
								series: {
									pie: { 
										show: true,
										radius: 1,
										label: {
											show: true,
											radius: 2/3,
											formatter: function(label, series){
												return '<div style="font-size:11px;text-align:center;padding:4px;color:white;">'+label+'<br/>'+(series.percent).toFixed(2)+'%</div>';
											},
											threshold: 0.1
										}
									}
								},
								legend: {
									show: false
								}
							});
						}, 
						error: function(data) { console.log(data); }, 
				});
			}
			
			
			
			if ($("#donut-chart").length) {
				var datebegin = $('.range_inputs .daterangepicker_start_input input.input-mini').val();
				var dateend = $('.range_inputs .daterangepicker_end_input input.input-mini').val();
				var datebeginoffical = datebegin[6]+datebegin[7]+datebegin[8]+datebegin[9]+'-'+datebegin[0]+datebegin[1]+'-'+datebegin[3]+datebegin[4];
				var dateendoffical = dateend[6]+dateend[7]+dateend[8]+dateend[9]+'-'+dateend[0]+dateend[1]+'-'+dateend[3]+dateend[4];
				var getUrl= "http://piwik.datamyze.com/?module=API&method=DevicesDetection.getType&idSite="+piwik_id+"&period=range&date="+datebeginoffical+","+dateendoffical+"&format=JSON&token_auth=717135ae2ebfd8f313284614f70a6765";
				
				$.ajaxSetup({ 
					scriptCharset: "UTF-8" , 
					contentType: "application/json; charset=UTF-8",
					type:"GET"
				});
				$("#donut-chart").html('<img src="../img/loading2.gif" />');
				$.ajax({
					url: getUrl,
					crossDomain:true,
					dataType : 'jsonp',
					jsonp : 'jsoncallback',
					//jsonpCallback  : 'foo',
					crossDomain : true,
						success: function(data) {
							data.forEach(function(entry) {
								entry.data = entry.sum_visit_length;
							});
							$.plot($("#donut-chart"), data,
								{
									colors: [lightBlue, mediumBlue, darkBlue, darkPlum, "#FFFF00"],
									series: {
										pie: {
											innerRadius: 0.5,
											show: true
										}
									}
								});
							
						},
						error: function(data) { console.log(data); }, 
					});
					
				var data = [];
				var series = 3;
				for( var i = 0; i<series; i++)
				{
					data[i] = { label: "Series "+(i+1), data: Math.floor(Math.random()*100)+1 }
				}
			}
		}

$('#profile-opts .brand a').click(function(){
	var piwik_id = $(this).attr('data-piwik');
	if (datebegin = $('.range_inputs .daterangepicker_start_input input.input-mini').val() == $('.range_inputs .daterangepicker_end_input input.input-mini').val()){
			var datesearch = $('.range_inputs .daterangepicker_start_input input.input-mini').val();
			var datesearchoffical = datesearch[6]+datesearch[7]+datesearch[8]+datesearch[9]+'-'+datesearch[0]+datesearch[1]+'-'+datesearch[3]+datesearch[4];
			if ($("#barchart").length) {
				var getUrl= "http://piwik.datamyze.com/?module=API&method=UserSettings.getResolution&idSite="+piwik_id+"&period=day&date="+datesearchoffical+"&format=JSON&token_auth=717135ae2ebfd8f313284614f70a6765";
				$.ajaxSetup({ 
					scriptCharset: "UTF-8" , 
					contentType: "application/json; charset=UTF-8",
					type:"GET"
				});
				$("#barchart").html('<img src="../img/loading2.gif" />');
				$.ajax({
					url: getUrl,
					crossDomain:true,
					dataType : 'jsonp',
					jsonp : 'jsoncallback',
					//jsonpCallback  : 'foo',
					crossDomain : true,
					success: function(data) {
						for (var i=0;i<(data.length - 1);i++){
							for (var j=i+1;j<data.length;j++){ 
								if( data[i].sum_visit_length < data[j].sum_visit_length ){
									k = data[i];
									data[i] = data[j];
									data[j] = k;
								}
							}
						}
						var sum = 0;
						for (var i=0;i<(data.length);i++){ 	
							if (i>4){
								sum = sum + data[i].sum_visit_length;
								//data[i].sum_visit_length = 0;
								delete data[i];
							} else{
								
							}
						}
						data.length = 6;
						data.forEach(function(entry) {
							entry.data = entry.sum_visit_length;
						});
							
							data[5] = { bounce_count: 19,  data: sum , label: "Other", max_actions: 681, nb_actions: 1180, nb_uniq_visitors: 56 ,nb_visits: 56, nb_visits_converted: 0, sum_visit_length: sum };
							
							$.plot($("#barchart"), data,
							{
								colors: ["#0066FF","#009999","#660033", "#FF0000", "#99FF66" , "#FF66FF"],
								series: {
									pie: {
										show: true,
										label: {
											show: false,
											formatter: function(label, series){
												return '<div style="font-size:11px;text-align:center;padding:4px;color:white;">'+label+'<br/>'+Math.round(series.percent)+'%</div>';
											},
											threshold: 0.1
										}
									}
								},
								legend: {
									show: true,
									noColumns: 1, // number of colums in legend table
									labelFormatter: null, // fn: string -> string
									labelBoxBorderColor: "#444", // border color for the little label boxes
									container: null, // container (as jQuery object) to put legend in, null means default on top of graph
									position: "ne", // position of default legend container within plot
									margin: [5, 10], // distance from grid edge to default legend container within plot
									backgroundOpacity: 0 // set to 0 to avoid background
								},
								grid: {
									hoverable: false,
									clickable: false
								}
							});
						
					},
					error: function(data) {console.log(data);},
				});
			}
			
			if ($("#pie-chart").length) {
				
				var getUrl="http://piwik.datamyze.com/?module=API&method=DevicesDetection.getBrowserFamilies&idSite="+piwik_id+"&period=day&date="+datesearchoffical+"&format=JSON&token_auth=717135ae2ebfd8f313284614f70a6765";
				
				$.ajaxSetup({ 
					scriptCharset: "UTF-8" , 
					contentType: "application/json; charset=UTF-8",
					type:"GET"
				});
				$("#pie-chart").html('<img src="../img/loading2.gif" />');
				$.ajax({
					url: getUrl,
					crossDomain:true,
					dataType : 'jsonp',
					jsonp : 'jsoncallback',
					//jsonpCallback  : 'foo',
					crossDomain : true,
					success: function(data) {
						for (var i=0;i<(data.length - 1);i++){
							for (var j=i+1;j<data.length;j++){ 
								if( data[i].sum_visit_length < data[j].sum_visit_length ){
									k = data[i];
									data[i] = data[j];
									data[j] = k;
								}
							}
						}
						//console.log(data);
						d2 = [];
						var i = 0;
						data.forEach(function(entry) {
							entry.data = entry.sum_visit_length;
							kak = [i, entry.sum_visit_length]
							d2.push(kak);
							i++;
						});
						console.log(d2);
						$.plot($("#pie-chart"), [
							{
								series:{
									bars:{
										show:true
									}
								},
								data: d2, 
								//label: "d1",
								grid :{
									hoverable: true,
									clickable: true,
									tickcolor: "#dddddd",
									borderWidth:0
								},
								bars: {
									align: "center",
									show: true,
									horizontal:false,
									barWidth: 0.5,
									fill: true,
								},
								xaxis: {
									position: "top",
									tickSize : 4,
									ticks: ["zero", "one" ,"two", "three", "Four", "Five", "Six", "Seven","Eight", "Nine"]
								},
								
								color:  "#FA5833",
							}]);
					},
					error: function(data) {
						console.log(data);
					}
				});
			}
			/*
			if ($("#pie-chart").length) {
				var getUrl="http://piwik.datamyze.com/?module=API&method=DevicesDetection.getBrowserFamilies&idSite="+piwik_id+"&period=day&date="+datesearchoffical+"&format=JSON&token_auth=717135ae2ebfd8f313284614f70a6765";
				$.ajaxSetup({ 
					scriptCharset: "UTF-8" ,
					contentType: "application/json; charset=UTF-8",
					type:"GET"
				});
				$("#pie-chart").html('<img src="../img/loading2.gif" />');
				$.ajax({
					url: getUrl,
					crossDomain:true,
					dataType : 'jsonp',
					jsonp : 'jsoncallback',
					jsonpCallback  : 'foo',
					crossDomain : true,
						success: function(data) {
							data.forEach(function(entry) {
								entry.data = entry.sum_visit_length;
							});
							$.plot($("#pie-chart"), data,
							{
								colors: [lightBlue, mediumBlue, darkBlue, "#333", "#ccc" , "#FFFF00" ,"#FF0000","#f0f0f0","#66FF33"],
								series: {
									pie: {
										show: true,
										label: {
											show: false,
											formatter: function(label, series){
												return '<div style="font-size:11px;text-align:center;padding:4px;color:white;">'+label+'<br/>'+Math.round(series.percent)+'%</div>';
											},
											threshold: 0.1
										}
									}
								},
								legend: {
									show: true,
									noColumns: 1, // number of colums in legend table
									labelFormatter: null, // fn: string -> string
									labelBoxBorderColor: "#444", // border color for the little label boxes
									container: null, // container (as jQuery object) to put legend in, null means default on top of graph
									position: "ne", // position of default legend container within plot
									margin: [5, 10], // distance from grid edge to default legend container within plot
									backgroundOpacity: 0 // set to 0 to avoid background
								},
								grid: {
									hoverable: false,
									clickable: false
								}
							});
						}, 
						error: function(data) { console.log(data); }, 
				});
			}
			*/
			
			if ($("#area-chart").length) {
				var datebegin = $('.range_inputs .daterangepicker_start_input input.input-mini').val();
				var dateend = $('.range_inputs .daterangepicker_end_input input.input-mini').val();
				datebeginoffical = datebegin[6]+datebegin[7]+datebegin[8]+datebegin[9]+'-'+datebegin[0]+datebegin[1]+'-'+datebegin[3]+datebegin[4];
				dateendoffical = dateend[6]+dateend[7]+dateend[8]+dateend[9]+'-'+dateend[0]+dateend[1]+'-'+dateend[3]+dateend[4];
				
				var getUrl="http://piwik.datamyze.com/?module=API&method=UserSettings.getMobileVsDesktop&idSite="+piwik_id+"&period=day&date="+datesearchoffical+"&format=JSON&token_auth=717135ae2ebfd8f313284614f70a6765";
				console.log(getUrl);
				$.ajaxSetup({ 
					scriptCharset: "UTF-8" ,
					contentType: "application/json; charset=UTF-8",
					type:"GET"
				});
				$("#area-chart").html('<img src="../img/loading2.gif" />');
				$.ajax({
					url: getUrl,
					crossDomain:true,
					dataType : 'jsonp',
					jsonp : 'jsoncallback',
					jsonpCallback  : 'foo',
					crossDomain : true,
						success: function(data) {
							data.forEach(function(entry) {
								entry.data = entry.sum_visit_length;
							});
							$.plot($("#area-chart"), data,
							{
								colors: [ "#3366FF" ,"#009900","#FF0000"],
								series: {
									pie: { 
										show: true,
										radius: 1,
										label: {
											show: true,
											radius: 2/3,
											formatter: function(label, series){
												return '<div style="font-size:11px;text-align:center;padding:4px;color:white;">'+label+'<br/>'+(series.percent).toFixed(2)+'%</div>';
											},
											threshold: 0.1
										}
									}
								},
								legend: {
									show: false
								}
							});
						}, 
						error: function(data) { console.log(data); }, 
				});
			}
			
			if ($("#donut-chart").length) {
				var getUrl= "http://piwik.datamyze.com/?module=API&method=DevicesDetection.getType&idSite="+piwik_id+"&period=day&date="+datesearchoffical+"&format=JSON&token_auth=717135ae2ebfd8f313284614f70a6765";
				$.ajaxSetup({ 
					scriptCharset: "UTF-8" , 
					contentType: "application/json; charset=UTF-8",
					type:"GET"
				});
				$("#donut-chart").html('<img src="../img/loading2.gif" />');
				$.ajax({
					url: getUrl,
					crossDomain:true,
					dataType : 'jsonp',
					jsonp : 'jsoncallback',
					//jsonpCallback  : 'foo',
					crossDomain : true,
						success: function(data) {
							data.forEach(function(entry) {
								entry.data = entry.sum_visit_length;
							});
							$.plot($("#donut-chart"), data,
								{
									colors: [lightBlue, mediumBlue, darkBlue, darkPlum, "#FFFF00"],
									series: {
										pie: {
											innerRadius: 0.5,
											show: true
										}
									}
								});
							
						},
						error: function(data) { console.log(data); }, 
					});
					
				var data = [];
				var series = 3;
				for( var i = 0; i<series; i++)
				{
					data[i] = { label: "Series "+(i+1), data: Math.floor(Math.random()*100)+1 }
				}
			}
		}else {
			if ($("#barchart").length) {
				var datebegin = $('.range_inputs .daterangepicker_start_input input.input-mini').val();
				var dateend = $('.range_inputs .daterangepicker_end_input input.input-mini').val();
				var datebeginoffical = datebegin[6]+datebegin[7]+datebegin[8]+datebegin[9]+'-'+datebegin[0]+datebegin[1]+'-'+datebegin[3]+datebegin[4];
				var dateendoffical = dateend[6]+dateend[7]+dateend[8]+dateend[9]+'-'+dateend[0]+dateend[1]+'-'+dateend[3]+dateend[4];
				var getUrl= "http://piwik.datamyze.com/?module=API&method=UserSettings.getResolution&idSite="+piwik_id+"&period=range&date="+datebeginoffical+","+dateendoffical+"&format=JSON&token_auth=717135ae2ebfd8f313284614f70a6765";
				$.ajaxSetup({ 
					scriptCharset: "UTF-8" , 
					contentType: "application/json; charset=UTF-8",
					type:"GET"
				});
				$("#barchart").html('<img src="../img/loading2.gif" />');
				$.ajax({
					url: getUrl,
					crossDomain:true,
					dataType : 'jsonp',
					jsonp : 'jsoncallback',
					//jsonpCallback  : 'foo',
					crossDomain : true,
					success: function(data) {
						for (var i=0;i<(data.length - 1);i++){
							for (var j=i+1;j<data.length;j++){ 
								if( data[i].sum_visit_length < data[j].sum_visit_length ){
									k = data[i];
									data[i] = data[j];
									data[j] = k;
								}
							}
						}
						var sum = 0;
						for (var i=0;i<(data.length);i++){ 	
							if (i>4){
								sum = sum + data[i].sum_visit_length;
								//data[i].sum_visit_length = 0;
								delete data[i];
							} else{
								
							}
						}
						data.length = 6;
						data.forEach(function(entry) {
							entry.data = entry.sum_visit_length;
						});
							
							data[5] = { bounce_count: 19,  data: sum , label: "Other", max_actions: 681, nb_actions: 1180, nb_uniq_visitors: 56 ,nb_visits: 56, nb_visits_converted: 0, sum_visit_length: sum };
							
							$.plot($("#barchart"), data,
							{
								colors: ["#0066FF","#009999","#660033", "#FF0000", "#99FF66" , "#FF66FF"],
								series: {
									pie: {
										show: true,
										label: {
											show: false,
											formatter: function(label, series){
												return '<div style="font-size:11px;text-align:center;padding:4px;color:white;">'+label+'<br/>'+Math.round(series.percent)+'%</div>';
											},
											threshold: 0.1
										}
									}
								},
								legend: {
									show: true,
									noColumns: 1, // number of colums in legend table
									labelFormatter: null, // fn: string -> string
									labelBoxBorderColor: "#444", // border color for the little label boxes
									container: null, // container (as jQuery object) to put legend in, null means default on top of graph
									position: "ne", // position of default legend container within plot
									margin: [5, 10], // distance from grid edge to default legend container within plot
									backgroundOpacity: 0 // set to 0 to avoid background
								},
								grid: {
									hoverable: false,
									clickable: false
								}
							});
						
					},
					error: function(data) {console.log(data);},
				});
			}
			
			if ($("#pie-chart").length) {
				//piwik_id
				var datebegin = $('.range_inputs .daterangepicker_start_input input.input-mini').val();
				var dateend = $('.range_inputs .daterangepicker_end_input input.input-mini').val();
				var datebeginoffical = datebegin[6]+datebegin[7]+datebegin[8]+datebegin[9]+'-'+datebegin[0]+datebegin[1]+'-'+datebegin[3]+datebegin[4];
				var dateendoffical = dateend[6]+dateend[7]+dateend[8]+dateend[9]+'-'+dateend[0]+dateend[1]+'-'+dateend[3]+dateend[4];
				var getUrl= "http://piwik.datamyze.com/?module=API&method=UserSettings.getResolution&idSite="+piwik_id+"&period=range&date="+datebeginoffical+","+dateendoffical+"&format=JSON&token_auth=717135ae2ebfd8f313284614f70a6765";
				
				var getUrl="http://piwik.datamyze.com/?module=API&method=DevicesDetection.getBrowserFamilies&idSite="+piwik_id+"&period=range&date="+datebeginoffical+","+dateendoffical+"&format=JSON&token_auth=717135ae2ebfd8f313284614f70a6765";
				
				$.ajaxSetup({ 
					scriptCharset: "UTF-8" , 
					contentType: "application/json; charset=UTF-8",
					type:"GET"
				});
				$("#pie-chart").html('<img src="../img/loading2.gif" />');
				$.ajax({
					url: getUrl,
					crossDomain:true,
					dataType : 'jsonp',
					jsonp : 'jsoncallback',
					//jsonpCallback  : 'foo',
					crossDomain : true,
					success: function(data) {
						for (var i=0;i<(data.length - 1);i++){
							for (var j=i+1;j<data.length;j++){ 
								if( data[i].sum_visit_length < data[j].sum_visit_length ){
									k = data[i];
									data[i] = data[j];
									data[j] = k;
								}
							}
						}
						//console.log(data);
						d2 = [];
						var i = 0;
						data.forEach(function(entry) {
							entry.data = entry.sum_visit_length;
							kak = [i, entry.sum_visit_length]
							d2.push(kak);
							i++;
						});
						console.log(d2);
						$.plot($("#pie-chart"), [
							{
								series:{
									bars:{
										show:true
									}
								},
								data: d2, 
								//label: "d1",
								grid :{
									hoverable: true,
									clickable: true,
									tickcolor: "#dddddd",
									borderWidth:0
								},
								bars: {
									align: "center",
									show: true,
									horizontal:false,
									barWidth: 0.5,
									fill: true,
								},
								xaxis: {
									position: "top",
									tickSize : 4,
									ticks: ["zero", "one" ,"two", "three", "Four", "Five", "Six", "Seven","Eight", "Nine"]
								},
								
								color:  "#FA5833",
							}]);
					},
					error: function(data) {
						console.log(data);
					}
				});
			}
			/*
			if ($("#pie-chart").length) {
				var datebegin = $('.range_inputs .daterangepicker_start_input input.input-mini').val();
				var dateend = $('.range_inputs .daterangepicker_end_input input.input-mini').val();
				datebeginoffical = datebegin[6]+datebegin[7]+datebegin[8]+datebegin[9]+'-'+datebegin[0]+datebegin[1]+'-'+datebegin[3]+datebegin[4];
				dateendoffical = dateend[6]+dateend[7]+dateend[8]+dateend[9]+'-'+dateend[0]+dateend[1]+'-'+dateend[3]+dateend[4];

				var getUrl="http://piwik.datamyze.com/?module=API&method=DevicesDetection.getBrowserFamilies&idSite="+piwik_id+"&period=range&date="+datebeginoffical+","+dateendoffical+"&format=JSON&token_auth=717135ae2ebfd8f313284614f70a6765";
				$.ajaxSetup({ 
					scriptCharset: "UTF-8" ,
					contentType: "application/json; charset=UTF-8",
					type:"GET"
				});
				$("#pie-chart").html('<img src="../img/loading2.gif" />');
				$.ajax({
					url: getUrl,
					crossDomain:true,
					dataType : 'jsonp',
					jsonp : 'jsoncallback',
					jsonpCallback  : 'foo',
					crossDomain : true,
						success: function(data) {
							data.forEach(function(entry) {
								entry.data = entry.sum_visit_length;
							});
							$.plot($("#pie-chart"), data,
							{
								colors: [lightBlue, mediumBlue, darkBlue, "#333", "#ccc" , "#FFFF00" ,"#FF0000","#f0f0f0","#66FF33"],
								series: {
									pie: {
										show: true,
										label: {
											show: false,
											formatter: function(label, series){
												return '<div style="font-size:11px;text-align:center;padding:4px;color:white;">'+label+'<br/>'+Math.round(series.percent)+'%</div>';
											},
											threshold: 0.1
										}
									}
								},
								legend: {
									show: true,
									noColumns: 1, // number of colums in legend table
									labelFormatter: null, // fn: string -> string
									labelBoxBorderColor: "#444", // border color for the little label boxes
									container: null, // container (as jQuery object) to put legend in, null means default on top of graph
									position: "ne", // position of default legend container within plot
									margin: [5, 10], // distance from grid edge to default legend container within plot
									backgroundOpacity: 0 // set to 0 to avoid background
								},
								grid: {
									hoverable: false,
									clickable: false
								}
							});
						}, 
						error: function(data) { console.log(data); }, 
				});
			}
			*/
			if ($("#area-chart").length) {
				var datebegin = $('.range_inputs .daterangepicker_start_input input.input-mini').val();
				var dateend = $('.range_inputs .daterangepicker_end_input input.input-mini').val();
				datebeginoffical = datebegin[6]+datebegin[7]+datebegin[8]+datebegin[9]+'-'+datebegin[0]+datebegin[1]+'-'+datebegin[3]+datebegin[4];
				dateendoffical = dateend[6]+dateend[7]+dateend[8]+dateend[9]+'-'+dateend[0]+dateend[1]+'-'+dateend[3]+dateend[4];

				
				var getUrl="http://piwik.datamyze.com/?module=API&method=UserSettings.getMobileVsDesktop&idSite="+piwik_id+"&period=range&date="+datebeginoffical+","+dateendoffical+"&format=JSON&token_auth=717135ae2ebfd8f313284614f70a6765";
				$.ajaxSetup({ 
					scriptCharset: "UTF-8" ,
					contentType: "application/json; charset=UTF-8",
					type:"GET"
				});
				$("#area-chart").html('<img src="../img/loading2.gif" />');
				$.ajax({
					url: getUrl,
					crossDomain:true,
					dataType : 'jsonp',
					jsonp : 'jsoncallback',
					jsonpCallback  : 'foo',
					crossDomain : true,
						success: function(data) {
							data.forEach(function(entry) {
								entry.data = entry.sum_visit_length;
							});
							$.plot($("#area-chart"), data,
							{
								colors: [ "#3366FF" ,"#009900","#FF0000"],
								series: {
									pie: { 
										show: true,
										radius: 1,
										label: {
											show: true,
											radius: 2/3,
											formatter: function(label, series){
												return '<div style="font-size:11px;text-align:center;padding:4px;color:white;">'+label+'<br/>'+(series.percent).toFixed(2)+'%</div>';
											},
											threshold: 0.1
										}
									}
								},
								legend: {
									show: false
								}
							});
						}, 
						error: function(data) { console.log(data); }, 
				});
			}
			
			if ($("#donut-chart").length) {
				var datebegin = $('.range_inputs .daterangepicker_start_input input.input-mini').val();
				var dateend = $('.range_inputs .daterangepicker_end_input input.input-mini').val();
				var datebeginoffical = datebegin[6]+datebegin[7]+datebegin[8]+datebegin[9]+'-'+datebegin[0]+datebegin[1]+'-'+datebegin[3]+datebegin[4];
				var dateendoffical = dateend[6]+dateend[7]+dateend[8]+dateend[9]+'-'+dateend[0]+dateend[1]+'-'+dateend[3]+dateend[4];
				var getUrl= "http://piwik.datamyze.com/?module=API&method=DevicesDetection.getType&idSite="+piwik_id+"&period=range&date="+datebeginoffical+","+dateendoffical+"&format=JSON&token_auth=717135ae2ebfd8f313284614f70a6765";
				
				$.ajaxSetup({ 
					scriptCharset: "UTF-8" , 
					contentType: "application/json; charset=UTF-8",
					type:"GET"
				});
				$("#donut-chart").html('<img src="../img/loading2.gif" />');
				$.ajax({
					url: getUrl,
					crossDomain:true,
					dataType : 'jsonp',
					jsonp : 'jsoncallback',
					//jsonpCallback  : 'foo',
					crossDomain : true,
						success: function(data) {
							data.forEach(function(entry) {
								entry.data = entry.sum_visit_length;
							});
							$.plot($("#donut-chart"), data,
								{
									colors: [lightBlue, mediumBlue, darkBlue, darkPlum, "#FFFF00"],
									series: {
										pie: {
											innerRadius: 0.5,
											show: true
										}
									}
								});
							
						},
						error: function(data) { console.log(data); }, 
					});
					
				var data = [];
				var series = 3;
				for( var i = 0; i<series; i++)
				{
					data[i] = { label: "Series "+(i+1), data: Math.floor(Math.random()*100)+1 }
				}
			}
		}
});